package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.common.anno.OperLog;
import com.atguigu.spzx.manager.service.FileService;
import com.atguigu.spzx.model.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "文件管理模块")
@RestController
@RequestMapping("/admin/file")
public class FileController {
    @Resource
    FileService fileService;
    //MultipartFile:用来接收前端上传的一个文件表单项   file表示前端上传的表单项name值
    @OperLog(title = "文件管理-文件上传" , isSaveRequestParams = false
            ,businessType = 1)
    @Operation(summary = "文件上传接口")
    //参数1：表示前端上传的文件    参数2：表示上传文件保存到桶内的哪个目录下
    @PostMapping("upload")
    public Result upload(MultipartFile file , String module){
        //上传成功返回上传文件的地址
        String path = fileService.upload(file , module);
        return Result.ok().data(path);
    }
    @Operation(summary = "文件删除接口")
    //参数1：表示前端上传的文件    参数2：表示上传文件保存到桶内的哪个目录下
    @DeleteMapping("delete")
    public Result delete(String path){
        //上传成功返回上传文件的地址
        fileService.delete(path);
        return Result.ok();
    }
}
